package sample.testTimeLine
{
	import com.bit101.components.TextArea;

	import flash.display.Sprite;
	import flash.events.MouseEvent;

	import org.abc.uiCore.AbcBtn;
	import org.abc.uiCore.AbcDynamicBtn;
	import org.abc.uiCore.TimeLineView;
	import org.abc.uiCore.event.TimelineEvent;
	import org.abc.uiCore.vo.Vo;

	/**
	 * @describe  	...
	 * @author  	Mr.zheng
	 * @website 	http://blog.sina.com.cn/zihua2007
	 * @time		2011-8-11 13:10
	 */
	public class TestTimeLine extends Sprite
	{
		private var animal:TimeLineView;
		private var txt:TextArea;

		public function TestTimeLine()
		{
			var btn:AbcBtn=new AbcBtn(new BtnMc);
			addChild(btn);
			btn.name="btn";

			var btn2:AbcBtn=new AbcBtn(new BtnMc);
			addChild(btn2);
			btn2.name="btn2";
			btn2.x=100;

			var btn3:AbcDynamicBtn=new AbcDynamicBtn(new NormalBtn, "动态按钮");
			addChild(btn3);
			btn3.name="btn3";
			btn3.y=50;

			txt=new TextArea(this, 200, 0, "结果显示：");

			animal=new TimeLineView(new AnimalMc);
			addChild(animal);
			animal.y=100;

			btn.addEventListener(MouseEvent.CLICK, onBtnClick);
			btn2.addEventListener(MouseEvent.CLICK, onBtnClick);
			btn2.timeLineMc.addEventListener(MouseEvent.CLICK, onBtnClick);
			animal.addEventListener(TimelineEvent.END_REACHED, onEndReached);
			animal.addEventListener(TimelineEvent.LABEL_REACHED, onLabel);
			animal.addEventListener(TimelineEvent.GOTO_LABEL_REACHED, onGotoAndStop);
		}

		/* public function */

		/* override function */

		/* private function */
		private function onBtnClick(e:MouseEvent):void
		{
			if (e.currentTarget.name == "btn")
			{
				animal.gotoAndPlay("t5");
			}
			if (e.currentTarget.name == "btn2")
			{
				var vo:Vo=new Vo();
				vo.data["info"]="param info.";
				animal.gotoAndStop("t20", vo, onGotoAndStop2, 10, "这是10");
			}
			if (e.currentTarget.name == "btn3")
			{

			}

		}

		private function onEndReached(e:TimelineEvent):void
		{
			txt.text+="\nthe end.";
		}

		private function onLabel(e:TimelineEvent):void
		{
			txt.text+="\nlabel:" + e.currentFrame + e.currentLabel + e.currentTarget;
		}

		private function onGotoAndStop(e:TimelineEvent):void
		{
			txt.text+="\ngotoAndStop:" + e.currentFrame + e.currentLabel + e.data.data["info"];
		}

		private function onGotoAndStop2(vars:Array):void
		{
			trace("onGotoAndStop2:" + vars);
		}
	}

}
